package test_junit_shop;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import util.BaseDriver;

import java.util.List;

/**
 * Created by Eric on 2018/2/5.
 * 门店-商城收银台
 */
public class ShopCashier extends BaseDriver{
    private static ShopCashier sc = new ShopCashier();
    public static ShopCashier getInstance(){
        return sc;
    }

    public void pay(String customerName, String productName, String amount) throws InterruptedException {
        driver.switchTo().defaultContent();
        List<WebElement> frameList = driver.findElements(By.xpath("//iframe[@name='iframeundefined']"));
        driver.switchTo().frame(frameList.get(frameList.size() - 1));

        driver.findElement(By.id("search_name")).sendKeys(customerName.substring(0, 2));
        Thread.sleep(1000);
        driver.findElement(By.xpath(String.format("//i[contains(text(), '%s')]", customerName))).click();
        Thread.sleep(1000);

        driver.findElement(By.xpath("//input[@placeholder='输入产品关键词']")).sendKeys(productName.substring(0, 2));
        Thread.sleep(1000);
        driver.findElement(By.xpath(String.format("//i[contains(text(), '%s')]", productName))).click();
        Thread.sleep(1000);
        driver.findElement(By.xpath("//tbody[@id='tbody_cont']/tr[1]/td[4]/input")).sendKeys(amount);
        Thread.sleep(1000);
        driver.findElement(By.id("quickPay")).click();

        Thread.sleep(2000);
        driver.switchTo().frame(0);
        driver.findElement(By.xpath("//tbody[@id='shortcutPay']/tr[2]/td[1]/label[1]/input")).click();

        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
        Thread.sleep(1000);

        driver.switchTo().parentFrame();
        driver.findElement(By.linkText("确定")).click();
        Thread.sleep(1000);
    }
}
